package fem2.pre_and_post;

import java.io.IOException;

import org.junit.Test;

import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshUtilities;
import fem2.mesh_and_topology.LineSpatialCriteria;
import fem2.mesh_and_topology.SpatialCriteria;

public class RefineQuadMeshGeneratorTest {

	@Test
	public void test1() {
		// MeshGenerator mg = new RefinerQuadMeshGenerator(0, 0, 1, 1, 0, 3); //
		// works correctly
		MeshGenerator mg = new RefineQuadMeshGenerator(1, 0, 1, 1, Math.PI / 2, 3);
		Mesh mesh = mg.getMesh(2);

		try {
			MeshUtilities.writeGiDMesh(mesh, "/home/hbui/temp/quad-mesh.msh");
		} catch (IOException e) {
			throw new Error("write fail");
		}
	}

	@Test
	public void test2() {
		MeshGenerator mg1 = new PatchMeshGenerator(3, 5, 0, 0, 50, 25);
		Mesh mesh1 = mg1.getMesh(2);

		MeshGenerator mg2 = new RefineQuadMeshGenerator(100, 100, 25, 50, -Math.PI / 2, 4);
		Mesh mesh2 = mg2.getMesh(2);

		SpatialCriteria c1 = new LineSpatialCriteria(100, 0, 0, 1);
		mesh1 = MeshUtilities.joinMesh(mesh1, mesh2, c1);

		MeshGenerator mg3 = new PatchMeshGenerator(13, 13, 150, 0, 12.5, 25.0 / 3);
		Mesh mesh3 = mg3.getMesh(2);

		SpatialCriteria c2 = new LineSpatialCriteria(150, 0, 0, 1);
		mesh1 = MeshUtilities.joinMesh(mesh1, mesh3, c2);

		MeshGenerator mg4 = new RefineQuadMeshGenerator(350, 0, 25, 50, Math.PI / 2, 4);
		Mesh mesh4 = mg4.getMesh(2);

		SpatialCriteria c3 = new LineSpatialCriteria(300, 0, 0, 1);
		mesh1 = MeshUtilities.joinMesh(mesh1, mesh4, c3);

		MeshGenerator mg5 = new PatchMeshGenerator(3, 5, 350, 0, 50, 25);
		Mesh mesh5 = mg5.getMesh(2);

		SpatialCriteria c4 = new LineSpatialCriteria(350, 0, 0, 1);
		mesh1 = MeshUtilities.joinMesh(mesh1, mesh5, c4);

		try {
			MeshUtilities.writeGiDMesh(mesh1,
					"/home/hbui/kratos_janosch/three-point-test-without-notch.gid/quad-mesh.msh");
		} catch (IOException e) {
			throw new Error("write fail");
		}
	}
}
